package com.partsoft.dits;

import org.springframework.util.Assert;


public abstract class AbstractDataEdgeDescriptor implements DataEdgeDescriptor, Cloneable {

	private String messageCode;
	
	private boolean conversion = true;
	
	private String title;
	
	private String description;
	
	private String dataIdentityPrefix;
	
	private int ordinal = 0;
	
	public AbstractDataEdgeDescriptor() {}
	
	public String getMessageCode() {
		return messageCode;
	}

	public void setMessageCode(String messageCode) {
		Assert.notNull(messageCode, "消息编码不能为空");
		this.messageCode = messageCode.trim().toUpperCase();
	}
	
	public boolean isConversion() {
		return conversion;
	}

	public void setConversion(boolean conversion) {
		this.conversion = conversion;
	}

	public boolean isNoConversion() {
		return !isConversion();
	}

	public void setNoConversion(boolean  noConversion) {
		setConversion(!noConversion);
	}
	
	
	@Override
	public AbstractDataEdgeDescriptor clone() {
		try {
			return (AbstractDataEdgeDescriptor) super.clone();
		} catch (CloneNotSupportedException e) {
			return null;
		}
	}
	
	public String getDescription() {
		return description == null ? "" : description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	public int getOrdinal() {
		return ordinal;
	}

	public void setOrdinal(int ordinal) {
		this.ordinal = ordinal;
	}

	public String getTitle() {
		return title == null ? "" : title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
	public String getDataIdentityPrefix() {
		return dataIdentityPrefix;
	}

	public void setDataIdentityPrefix(String dataIdentityPrefix) {
		this.dataIdentityPrefix = dataIdentityPrefix;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AbstractDataEdgeDescriptor other = (AbstractDataEdgeDescriptor) obj;
		if (getId() == null) {
			if (other.getId() != null)
				return false;
		} else if (!getId().equals(other.getId()))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		return String.format("数据集成(%s)", getId());
	}
	
}
